package com.ptu.mapper;

import com.github.pagehelper.Page;
import com.ptu.dto.UserDTO;
import com.ptu.entity.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {

    @Insert("insert into user(username,password,phone,gender,img,create_time,update_time) values(#{username},#{password},#{phone},#{gender},#{img},now(),now())")
    void register(UserDTO userDTO);

    //void login(UserLoginDTO userLoginDTO);

    @Select("SELECT COUNT(*) > 0 FROM user WHERE phone = #{phone}")
    boolean isPhoneExist(String phone);


    @Select("SELECT * FROM user WHERE phone = #{phone}")
    User getUserByPhone(String phone);

    //@Update("UPDATE user SET username = #{username}, phone = #{phone}, gender = #{gender}, password = #{password}, img = #{img}, update_time = now() WHERE id = #{id}")

    void update(UserDTO userDTO);

    @Update("UPDATE user SET img = #{img} WHERE id = #{id}")
    void updateById(Integer id, String img);

    @Select("SELECT * FROM user WHERE id = #{id}")
    UserDTO getUser(Integer id);

    Page<User> pageQuery(String phone, String userName);

    @Select("SELECT * FROM user WHERE id = #{id}")
    User adminGetUser(Integer id);

    void adminUpdate(User user);

    @Delete("DELETE FROM user WHERE id = #{id}")
    void delete(Integer id);

    @Insert("INSERT INTO user (username, password, phone, gender, img, create_time, update_time) VALUES (#{username}, #{password}, #{phone}, #{gender}, #{img}, now(), now())")
    void adminAdd(UserDTO user);

    @Select("SELECT id FROM user WHERE username = #{userName}")
    User selectIdByName(String userName);

    @Select("SELECT * FROM user WHERE username = #{adminName} AND password = #{password}")
    User adminLogin(String adminName, String password);


}
